using Brick;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Assets.Scripts.GDK
{
	public class gdk_runTime
	{
		public static IEnumerator setInterval(Action action, float delay)
		{
			return gdk_coroutine.Instance.StartCoroutine(demoRepeatFun(delay, action));
		}

		public static IEnumerator setTimeOut(Action action, float delay, GameObject item1 = null, GameObject item2 = null)
		{
			bindListNodeValidType(item1, item2);
			return gdk_coroutine.Instance.StartCoroutine(demoFun(delay, action));
		}

		public static void clear(IEnumerator ie)
		{
			gdk_coroutine.Instance.StopCoroutine(ie);
		}

		private static IEnumerator demoFun(float wait, Action callback)
		{
			yield return new gdk_waitForSeconds(wait);
			callback();
		}

		private static IEnumerator demoRepeatFun(float wait, Action callback)
		{
			while (true)
			{
				yield return new gdk_waitForSeconds(wait);
				callback();
			}
		}

		private static void bindListNodeValidType(GameObject item1, GameObject item2)
		{
			List<GameObject> list = new List<GameObject>();
			list.Add(item1);
			list.Add(item2);
			List<GameObject> list2 = list;
			for (int i = 0; i < list2.Count; i++)
			{
				GameObject gameObject = list2[i];
				if ((bool)gameObject)
				{
					gdk_valid gdk_valid = gameObject.GetComponent<gdk_valid>();
					if (!gdk_valid)
					{
						gdk_valid = gameObject.AddComponent<gdk_valid>();
					}
					gdk_valid.isValid = true;
				}
			}
		}

		public static bool isValid(GameObject item)
		{
			if ((bool)item)
			{
				gdk_valid component = item.GetComponent<gdk_valid>();
				if ((bool)component)
				{
					return component.isValid;
				}
			}
			return false;
		}
	}
}
